--
-- Author: bin.zhao
-- Date: 2018-07-11 16:33:01
--
-- ExplockView
--

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

ClassRef.VIEW_ROOT_RES = Res.ExpLockScene

function ClassRef:init()

	self.lockLevel 				= self._ui["icon_1/num"]
	self.currentExp				= self._ui["Panel/Panel_exp/exp"]
	--解锁提示
	self.tipUnlockTime			= self._ui["Panel/text"]
	--经验池提示
	self.expTipView				= self._ui["Panel_tips"]
	self.tipExpPoor				= self._ui["Panel_tips/text"]
	self.tipExpPoor:setString(L("levelLockDesc"))

	self.btnConfirm				= self._ui.Button_queding
	self.btnConfirm:setTouchEnabled(true)
	self.btnConfirm:addClickEventListener(function()
			executeFunc(self._onCloseView)
		end)

	self.imgClickShowTip 		= self._ui["Panel/Panel_exp/bg_1"]
	self.imgClickShowTip:setTouchEnabled(true)
	self.imgClickShowTip:addClickEventListener(function()
			local isShow = self.expTipView:isVisible()
			self.expTipView:setVisible(not isShow)
		end)
end

-- 接口名不可更改，保持与viewBase一致
function ClassRef:getViewType()
    return app.mvc.VIEWTYPE_BLUR
end

function ClassRef:freshData(data)
	
	local lockLv = data.lockLevel
	local timeValue = data.unlockTime
	local poorExp = data.expPool or 0
	local serverTime = math.floor(app.session:getServerTime())
	local curTimeLast = timeValue - serverTime
	-- print("###########      timeValue     ",timeValue)
	-- print("###########      timeValue     ",os.time())
	-- dump(TimeUtil.secondsToDate(timeValue))
	local day = 0
	local hour = 0
	if curTimeLast > 0 then
		 day = math.floor(curTimeLast / 86400)
		
	    if day >= 1 then
	        local gap = curTimeLast % 86400
	        hour = math.floor(gap/3600)
	    else
	    	hour = math.floor(curTimeLast/3600)
		end

		if hour == 0 and day == 0 then
			hour = 1
		end

	    self.tipUnlockTime:setString(string.format(L("levelLockTime"),day,hour))
	else
		self.tipUnlockTime:setVisible(false)
	end
	self.lockLevel:setString(lockLv)
	self.currentExp:setString(string.format(L("levelLockValue"),poorExp))
	
end

function ClassRef:onExit()

end

function ClassRef:onEnter()

end

return ClassRef
